$def with (course,submissions,allowed_groups,groups,users,mygroup,msg, error)

$#
$# This file is part of INGInious. See the LICENSE and the COPYRIGHTS files for
$# more information about the licensing of this file.
$#

$var title:  $:course.get_name(user_manager.session_language())
$ username = user_manager.session_username()

$# Left column content
$def ColumnF():
    $:template_helper.call('course_menu',course=course, template_helper=template_helper)
    <h3>$:_("Current grade")</h3>
    <div class="progress mb-3">
        $ grade=user_manager.get_course_cache(username, course)["grade"]
        <div class="progress-bar progress-bar-success" aria-valuenow="$int(grade)" aria-valuemin="0" aria-valuemax="100" style="width: $grade%">
            $int(grade)%
        </div>
    </div>

    <h3>$:_("Last tried exercises")</h3>

    <div class="list-group mb-3">
        $if submissions:
            $for submission in submissions:
                <a class="list-group-item
                    $if submission['status'] == 'done' and submission['result'] == 'success':
                        list-group-item-success
                    $elif submission['status'] == 'done' and submission['result'] == 'save':
                        list-group-item-info
                    $elif submission['status'] == 'waiting':
                        list-group-item-warning
                    $else:
                        list-group-item-danger
                    "
                    href="$get_homepath()/course/$submission['courseid']/$submission['taskid']">
                    $submission['taskname']
                </a>
        $else:
            <a class="list-group-item disabled submission-empty">$:_("No submissions")</a>
    </div>
    $if course.allow_unregister():
        <div class="list-group">
            <a href="#" data-toggle="modal" data-target="#unregister_modal" class="list-group-item list-group-item-info">
                <i class="fa fa-user-times fa-fw"></i>&nbsp; $:_("Unregister from this course")
            </a>
        </div>
$var Column: $:ColumnF()

$def NavbarF():
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a  href="$get_homepath()/course/$course.get_id()">$course.get_name(user_manager.session_language())</a></li>
            <li class="breadcrumb-item active"><a href="#"><i class="fa fa-group"></i>
                $if mygroup is None:
                    $:_("Register for a group")
                $else:
                    $:_("Groups")
                <span class="sr-only">$:_("(current)")</span></a>
            </li>
        </ol>
    </nav>
$var Navbar: $:NavbarF()

$# Start content
<h2>$course.get_name(user_manager.session_language()) - $:_("Groups")</h2>
$if error:
    <div class="alert alert-danger alert-dismissable" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
        $:msg
    </div>
$elif msg:
    <div class="alert alert-success alert-dismissable" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
        $:msg
    </div>


$if mygroup and username in mygroup["students"]:
    <div class="card mb-3 border-info" >
        <div class="card-header text-white bg-info">
            $:_("My group : {}").format(mygroup["description"])
            $if course.can_students_choose_group():
            <div class="pull-right">
                <a href="?unregister_group" data-toggle="tooltip" data-placement="left" title=$:_('"Quit group"')>
                    <i style="color:white;" class="fa fa-user-times"></i>
                </a>
            </div>
        </div>

        <ul class="list-group list-group-flush">
        $for user in mygroup["students"]:
            <li class="list-group-item">
                $if users[user] is not None:
                    $users[user][0]
                    <div class="pull-right">
                        <a class="mailto" href="mailto:$users[user][1]" data-toggle="tooltip" data-placement="left" title=$:_('"Send an email"')>
                            <i class="fa fa-envelope-o"></i>
                        </a>
                    </div>
                $else:
                    $user
            </li>
        </ul>
    </div>

$elif not len(groups):
    <div class="alert alert-info alert-dismissable" role="alert">
        $:_("No set group in this course. If you think this is a mistake, please contact the course administrator.")
    </div>
$elif not len(allowed_groups):
    <div class="alert alert-info alert-dismissable" role="alert">
        $:_("Groups have been set up but you're not allowed to register in anyone. Please contact the course administrator.")
    </div>
$elif course.can_students_choose_group():
    <h3>$:_("My group")</h3>
    <div class="alert alert-warning alert-dismissable" role="alert">
        $:_("You're not registered to a group. Please consider registration in one of the group below to take part in all course activities. If no more group is available, please contact the course administrator.")
    </div>
$else:
    <h3>$:_("My group")</h3>
    <div class="alert alert-warning alert-dismissable" role="alert">
        $:_("You're not yet registered to a group. Please contact the course administrator for more information.")
    </div>

$if not len(allowed_groups) == 0:
    <h3 style="margin-bottom: 20px">$:_("All groups")</h3>
    $for index, group in enumerate(allowed_groups):
        <div class="card mb-3">
            $if not mygroup or username not in mygroup["students"] and (group["size"]-len(group["students"])) > 0 and course.can_students_choose_group():
                <div class="card-header bg-success text-white" id="heading_$index">
            $else:
                <div class="card-header" role="tab" id="heading_$index">

            $group["description"]
            $if not mygroup or username not in mygroup["students"] and (group["size"]-len(group["students"])) > 0 and course.can_students_choose_group():
                $:_("(available : {})").format(group["size"]-len(group["students"]))
                <div class="pull-right">
                    <a href="?register_group=$group['_id']" data-toggle="tooltip" data-placement="left" title="$:_('Join in')">
                        <i style="color:white;" class="fa fa-sign-in"></i>
                    </a>
                </div>
            </div>
            <ul class="list-group list-group-flush">

            $if len(group["students"]) == 0:
                <li class="list-group-item"><i>$:_("No registered member.")</i></li>
            $else:
                $for user in group["students"]:
                    <li class="list-group-item">
                        $if users[user] is not None:
                            $users[user][0]
                            <div class="pull-right">
                                <a class="mailto" href="mailto:$users[user][1]" data-toggle="tooltip" data-placement="left" title="$:_('Send an email')">
                                    <i class="fa fa-envelope-o"></i>
                                </a>
                            </div>
                        $else:
                            $user
                    </li>

            </ul>
         </div>

$:include.unregister_modal(course)
